package com.example.lanouhn.firstapp.activity.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lanouhn.firstapp.R;
import com.example.lanouhn.firstapp.activity.model.Comment;
import com.example.lanouhn.firstapp.activity.model.Goods;
import com.example.lanouhn.firstapp.activity.model.HomePage;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * 首页界面的最新商品的数据适配器
 */
public class CommentAdapter extends RecyclerView.Adapter {

    //上下文对象
    private Context context;
    //数据集合
    private List<Comment> list;

    public CommentAdapter(Context context, List<Comment> list) {
        this.context = context;
        this.list = list;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //加载布局
        RecyclerView.ViewHolder holder = null;

        holder = new VHolder(
                LayoutInflater.from(context).

                        inflate(R.layout.item_comment,null));

        return holder;
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {

        final VHolder vHolder = (VHolder) holder;
        //数据位置
        Comment comment = list.get(position);
        //设置数据 运用picasso获取图片
//        Picasso.with(context).load(comment.getGoods_image_url()).into(vHolder.imageView);
        vHolder.geval_addtime.setText(comment.getGeval_addtime());
        vHolder.geval_content.setText(comment.getGeval_content());
//        vHolder.geval_scores.setText(comment.getGeval_scores());
        vHolder.geval_frommembername.setText(comment.getGeval_frommembername());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    //定义VHolder类继承RecyclerView.ViewHolder
    class VHolder extends RecyclerView.ViewHolder{

        //时间
        private TextView geval_addtime;
        //评价内容
        private TextView geval_content ;
        //昵称
        private TextView geval_frommembername ;
        //星级
        private TextView geval_scores ;
        //绑定控件id
        public VHolder(View itemView) {
            super(itemView);
            geval_addtime = (TextView) itemView.findViewById(R.id.geval_addtime);
            geval_content = (TextView) itemView.findViewById(R.id.geval_content);
            geval_frommembername = (TextView) itemView.findViewById(R.id.geval_frommembername);
//            geval_scores = (TextView) itemView.findViewById(R.id.geval_scores);

        }
    }


}
